feat(unplugin): pre-bundle used icons into the Vue/Vite build#6635
Draft
benjamincanac wants to merge 2 commits into
Draft
feat(unplugin): pre-bundle used icons into the Vue/Vite build#6635benjamincanac wants to merge 2 commits into
benjamincanac wants to merge 2 commits into
Conversation
Embed the icons Nuxt UI uses at build time via a new `@nuxt/ui/vite` sub-plugin so they render during SSR and work fully offline with no runtime Iconify API fetch, mirroring what #6633 does on the Nuxt side. Adds an `icon.clientBundle` option to bundle your own icons on top of the defaults. Co-authored-by: Typed SIGTERM <145281501+typed-sigterm@users.noreply.github.com>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #5242 and supersedes #5894.
Context
On the Vue/Vite side, the icons Nuxt UI uses were never bundled, so
@iconify/vuefetched them from the Iconify API at runtime. That broke offline use, caused the SSR "icon appears after hydration" flash, and added network round-trips. This is the Vue equivalent of what #6633 wires up for Nuxt through@nuxt/icon's client bundle.What this does
A new
@nuxt/ui/vitesub-plugin (src/plugins/icons.ts) loads the SVG data at build time with@iconify/utilsand emits avirtual:nuxt-ui-iconsmodule that registers the inlined data through@iconify/vue'saddIcon. The vue-plugininstallruns it on both server and client, so the icons render synchronously during SSR and fully offline, while keeping thei-lucide-*string syntax.It reuses the
src/utils/icons.tshelpers from #6633 and applies the nuxt/icon#502 lesson by resolving collections from the Viteconfig.rootrather thanprocess.cwd(), so workspace and monorepo builds work too.Options
Bundling is on by default for Nuxt UI's own icons. You can extend or disable it:
Following the same decision as #6633, this does not add
@iconify-json/lucideas a hard dependency. Icons are bundled only when their collection is installed, and otherwise fall back to runtime loading. The SSR docs have been updated to explain this.How to test
@iconify-json/lucide.api.iconify.design.In this repo,
pnpm dev:vue:buildbundles all 42 default lucide icons into the output with their SVG bodies inlined.Notes
feat/pre-bundle-icons(feat: pre-bundle used icons into@nuxt/iconclient bundle #6633) so the diff shows only the Vue side. GitHub will retarget the base tov4once feat: pre-bundle used icons into@nuxt/iconclient bundle #6633 merges.vite-plugin-iconify-bundleinspired the approach.